package bigdata.kafka;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author sjw
 * @className a
 * @date 2021/5/8 9:01
 * @description: TODO
 */
public class a {
    public static void main(String[] args) {

        double ad=1.5,bd=0.5;
        System.out.println(ad-bd);


        String a="2021-08-01";
        if(a.length()>6)
        System.out.println(a.substring(0,7));


        long al=1619409600000L,bl=1619539199000L;
        double aa=0d;
        while (al<bl){
            System.out.println(new Date(al));
            aa+=0.5;
            if(aa>1) System.out.println("aaaa");
            al=al+43200000L;
        }
        Calendar c=Calendar.getInstance();
        c.set(2021,3,26,0,0);
        Date d1=c.getTime();
        c.set(2021,4,15,0,0);
         List<Date> sss=  getMonthList(d1,c.getTime());
        System.out.println(sss);
    }



    public static List<Date> getMonthList(Date fromDate, Date toDate) {
        List<Date> daysList = new ArrayList<>();
        Date startDate = fromDate;
        Date endDate = toDate;
        if (compareTwoDate(fromDate, toDate) > 0) {
            startDate = toDate;
            endDate = fromDate;
        }
        Date startMonthDay;
        Date endMonthDay;
//        try {
        startMonthDay = getFirstDayOfMonth(startDate);
        endMonthDay = getFirstDayOfMonth(endDate);
//        } catch (ParseException e) {
//            e.printStackTrace();
//            throw new ServiceException("日期格式转换失败");
//        }
        daysList.add(startMonthDay);
        // 获取下个月开始日期
        Date nextMonthDay = getCountedMonth(startMonthDay, "1");
        while (compareTwoDate(nextMonthDay, endMonthDay) <= 0) {
            daysList.add(nextMonthDay);
            nextMonthDay = getCountedMonth(nextMonthDay, "1");
        }
        return daysList;
    }


    public static Date getFirstDayOfMonth(Date strDate) {
        Calendar c = Calendar.getInstance();
        c.setTime(strDate);
        final int last = c.getActualMinimum(Calendar.DAY_OF_MONTH);
        c.set(Calendar.DAY_OF_MONTH, last);
        return c.getTime();
    }


    public static int compareTwoDate(Date fromDate, Date toDate) {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

//            Date fDate = sdf.parse(fromDate);
//            Date tDate = sdf.parse(toDate);
        if (fromDate.getTime() > toDate.getTime()) {
            return 1;
        } else if (fromDate.getTime() < toDate.getTime()) {
            return -1;
        } else {
            return 0;
        }

    }

    public static Date getCountedMonth(Date strDate, String delay) {
        Calendar currentDate = Calendar.getInstance();
        currentDate.setTime(strDate);
        currentDate.add(Calendar.MONTH, Integer.parseInt(delay));
        return currentDate.getTime();
    }


}
